package com.twoGroup.boot.controller;


import com.twoGroup.boot.pojo.Address;
import com.twoGroup.boot.service.AddressService;
import com.twoGroup.boot.service.imp.AddressServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/Address")
@Api(tags = "用户地址接口")
public class AddressController {
    public static Logger logger = LoggerFactory.getLogger(AddressController.class);
    @Autowired
    private AddressService addressService;

    //添加新的收件人
    @ApiOperation(value = "添加新的收件人(<=5)", notes = "传入userId(用户id)")
    @PostMapping("/addAddressee")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId",value = "用户id"),
                    @ApiImplicitParam(name="addressee",value = "收件人名字（长度1-6 跟nickname,可以不是真实姓名）"),
                    @ApiImplicitParam(name = "addresseeTelephone",value = "收件人手机号（11为且第一个值为1）"),
                    @ApiImplicitParam(name = "address",value = "收件人地址")
            }
    )
    @ResponseBody
    public int addAddressee(Integer userId, String addressee, String addresseeTelephone, String address){
        return addressService.addAddressee(userId, addressee, addresseeTelephone, address);
    }

    //删除某个收件人
    @ApiOperation(value = "删除某个收件人", notes = "传入addresseeId")
    @PostMapping("/deleteAddressee")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "addresseeId", value = "收件人id！！！可以由queryAllAddressee接口传入 该接口返回值是个集合 可以拿到对应的id")
            }
    )
    @ResponseBody
    public int deleteAddressee(Integer addresseeId){
       return addressService.deleteAddressee(addresseeId);
    }

    //删除所有收件人
    @ApiOperation(value = "删除所有收件人", notes = "传入userId(用户id)")
    @PostMapping("/deleteAllAddressee")
    @ResponseBody
    public int deleteAllAddressee(Integer userId){
       return addressService.deleteAllAddressee(userId);
    }

    //更改收件人信息
    @ApiOperation(value = "更改收件人的信息", notes = "传入userId(用户id)")
    @PostMapping("/updateAddressee")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "addresseeId",value = "收件人id（地址id 不是用户id 不是用户id 不是用户id！！！）"),
                    @ApiImplicitParam(name="addressee",value = "收件人名字（长度1-6 跟nickname,可以不是真实姓名）"),
                    @ApiImplicitParam(name = "addresseeTele",value = "收件人手机号"),
                    @ApiImplicitParam(name = "address",value = "收件人地址")
            }
    )
    @ResponseBody
    public int updateAddressee(Integer addresseeId, String addressee, String addresseeTele, String address){
        return addressService.updateAddressee(addresseeId, addressee, addresseeTele, address);
    }

    //查询所有的收件人
    @ApiOperation(value = "查询所有用户保存的地址", notes = "传入userId(用户id),返回address集合")
    @PostMapping("/queryAllAddressee")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId",value = "用户id")
            }
    )
    @ResponseBody
    public List<Address> queryAllAddressee(Integer userId){
        List<Address> addresses = addressService.queryAllAddressee(userId);
        for (Address address : addresses) {
            logger.info(String.valueOf(address));
        }
        return addresses;
    }
}
